package com.daoImpl;

import java.util.List;

import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.bean.ProcureProductCraft;
import com.dao.ProcureProductCraftDao;

/**
 * A data access object (DAO) providing persistence and search support for
 * ProcureProductCraft entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.bean.ProcureProductCraft
 * @author MyEclipse Persistence Tools
 */
public class ProcureProductCraftDaoImpl extends HibernateDaoSupport implements ProcureProductCraftDao {
	private static final Logger log = LoggerFactory
			.getLogger(ProcureProductCraftDaoImpl.class);
	// property constants
	public static final String PROC_ID = "procId";
	public static final String PART_ID = "partId";

	protected void initDao() {
		// do nothing
	}

	/* (non-Javadoc)
	 * @see com.daoImpl.ProcureProductCraftDao#save(com.bean.ProcureProductCraft)
	 */
	@Override
	public void save(ProcureProductCraft transientInstance) {
		log.debug("saving ProcureProductCraft instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.daoImpl.ProcureProductCraftDao#delete(com.bean.ProcureProductCraft)
	 */
	@Override
	public void delete(ProcureProductCraft persistentInstance) {
		log.debug("deleting ProcureProductCraft instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.daoImpl.ProcureProductCraftDao#findById(java.lang.Integer)
	 */
	@Override
	public ProcureProductCraft findById(java.lang.Integer id) {
		log.debug("getting ProcureProductCraft instance with id: " + id);
		try {
			ProcureProductCraft instance = (ProcureProductCraft) getHibernateTemplate()
					.get("com.bean.ProcureProductCraft", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.daoImpl.ProcureProductCraftDao#findByExample(com.bean.ProcureProductCraft)
	 */
	@Override
	public List findByExample(ProcureProductCraft instance) {
		log.debug("finding ProcureProductCraft instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.daoImpl.ProcureProductCraftDao#findByProperty(java.lang.String, java.lang.Object)
	 */
	@Override
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding ProcureProductCraft instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from ProcureProductCraft as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.daoImpl.ProcureProductCraftDao#findByProcId(java.lang.Object)
	 */
	@Override
	public List findByProcId(Object procId) {
		return findByProperty(PROC_ID, procId);
	}

	/* (non-Javadoc)
	 * @see com.daoImpl.ProcureProductCraftDao#findByPartId(java.lang.Object)
	 */
	@Override
	public List findByPartId(Object partId) {
		return findByProperty(PART_ID, partId);
	}

	/* (non-Javadoc)
	 * @see com.daoImpl.ProcureProductCraftDao#findAll()
	 */
	@Override
	public List findAll() {
		log.debug("finding all ProcureProductCraft instances");
		try {
			String queryString = "from ProcureProductCraft";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.daoImpl.ProcureProductCraftDao#merge(com.bean.ProcureProductCraft)
	 */
	@Override
	public ProcureProductCraft merge(ProcureProductCraft detachedInstance) {
		log.debug("merging ProcureProductCraft instance");
		try {
			ProcureProductCraft result = (ProcureProductCraft) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.daoImpl.ProcureProductCraftDao#attachDirty(com.bean.ProcureProductCraft)
	 */
	@Override
	public void attachDirty(ProcureProductCraft instance) {
		log.debug("attaching dirty ProcureProductCraft instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.daoImpl.ProcureProductCraftDao#attachClean(com.bean.ProcureProductCraft)
	 */
	@Override
	public void attachClean(ProcureProductCraft instance) {
		log.debug("attaching clean ProcureProductCraft instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static ProcureProductCraftDao getFromApplicationContext(
			ApplicationContext ctx) {
		return (ProcureProductCraftDao) ctx.getBean("ProcureProductCraftDaoImpl");
	}
}